package com.app.couponsharelife.ui.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import com.app.couponsharelife.R
import com.app.couponsharelife.data.bean.MissionBean
import com.app.couponsharelife.databinding.FraTribeItemBinding
import com.app.couponsharelife.ui.listener.OnClickListener

class TribeListAdapter(private val listener: OnClickListener) :
        androidx.recyclerview.widget.RecyclerView.Adapter<androidx.recyclerview.widget.RecyclerView.ViewHolder>() {

    val list = mutableListOf<MissionBean>()

    init {
        list.add(MissionBean("每日分享", "分享领券力值"))
        list.add(MissionBean("每日签到", "签到领券力"))
        list.add(MissionBean("邀请好友", "＋10永久券力值／人"))
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): androidx.recyclerview.widget.RecyclerView.ViewHolder {
        return ViewHolder(DataBindingUtil.inflate(
                LayoutInflater.from(parent.context), R.layout.fra_tribe_item, parent, false))
    }

    override fun getItemCount(): Int {
        return list.size
    }

    override fun onBindViewHolder(holder: androidx.recyclerview.widget.RecyclerView.ViewHolder, position: Int) {
        (holder as ViewHolder).databinding.tvContent.text = list[position].content
        holder.databinding.tvTitle.text = list[position].title
    }

    inner class ViewHolder(val databinding: FraTribeItemBinding) : androidx.recyclerview.widget.RecyclerView.ViewHolder(databinding.root) {
        init {
            databinding.root.setOnClickListener {
                if (adapterPosition != -1) {
                    listener.click(adapterPosition, list[adapterPosition].title)
                }
            }
        }
    }
}